package com.yugao.fintech.libra.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yugao.fintech.libra.system.model.rqrs.microapp.MicroAppBasePageReq;
import com.yugao.fintech.libra.system.model.rqrs.microapp.MicroAppResp;
import com.yugao.fintech.libra.system.model.rqrs.microapp.MicroAppSaveReq;
import com.yugao.fintech.libra.system.model.rqrs.microapp.MicroAppUpdateReq;
import com.yugao.fintech.libra.system.service.MicroAppService;
import com.yugao.fintech.meheco.core.domain.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 微应用(目前为实验性功能, 需要深入探索)
 */
@RestController
@RequestMapping("/microApp")
@Tag(name = "微应用")
public class MicroAppController {
    @Autowired
    private MicroAppService microAppService;

    @Operation(description = "分页微应用")
    @GetMapping("/pageMicroApp")
    public ResultVO<IPage<MicroAppResp>> pageMicroApp(@Validated MicroAppBasePageReq req) {
        return ResultVO.success(microAppService.pageMicroApp(req));
    }

    @Operation(description = "通过id查找微应用")
    @GetMapping("/getMicroApp")
    public ResultVO<MicroAppResp> getMicroApp(@RequestParam(value = "id") Long id) {
        return ResultVO.success(microAppService.getMicroApp(id));
    }

    @Operation(description = "保存微应用")
    @PostMapping("/saveMicroApp")
    public ResultVO<?> saveMicroApp(@Validated @RequestBody MicroAppSaveReq req) {
        return ResultVO.success(microAppService.saveMicroApp(req));
    }

    @Operation(description = "更新微应用")
    @PostMapping("/updateMicroApp")
    public ResultVO<?> updateMicroApp(@Validated @RequestBody MicroAppUpdateReq req) {
        return ResultVO.success(microAppService.updateMicroApp(req));
    }

    @Operation(description = "批量删除微应用")
    @DeleteMapping("/batchDeleteMicroApp")
    public ResultVO<?> batchDeleteMicroApp(@RequestParam(value = "ids") List<Long> ids) {
        return ResultVO.success(microAppService.batchDeleteMicroApp(ids));
    }

    @Operation(description = "删除微应用")
    @DeleteMapping("/deleteMicroApp")
    public ResultVO<?> deleteMicroApp(@RequestParam(value = "id") Long id) {
        return ResultVO.success(microAppService.deleteMicroApp(id));
    }
}
